﻿Imports System.Data.SqlClient

Public Class DuToanCt
    Private sSoDt As String
    Private iMa As Integer
    Private nSl As Decimal


    Public Property SoDt() As String
        Get
            Return sSoDt
        End Get
        Set(ByVal Value As String)
            sSoDt = Value
        End Set
    End Property

    Public Property Ma() As Integer
        Get
            Return iMa
        End Get
        Set(ByVal Value As Integer)
            iMa = Value
        End Set
    End Property

    Public Property Sl() As Decimal
        Get
            Return nSl
        End Get
        Set(ByVal Value As Decimal)
            nSl = Value
        End Set
    End Property

End Class

Public Class DuToanCtF

    Public Function GetWhereSoDt(ByVal SoDt As String) As DataTable
        Dim myProjCnn As New ProjectConnection
        Dim myCnn As New SqlConnection
        Dim myDat As New SqlDataAdapter
        Dim myDtb As New DataTable

        myCnn = myProjCnn.GetConnection
        myCnn.Open()

        Dim myCmd As New SqlCommand
        With myCmd
            .Connection = myCnn
            .CommandType = CommandType.StoredProcedure
            .CommandText = "DuToanCt_GetWhereSoDt"

            .Parameters.Add(New SqlClient.SqlParameter("@sodt", SqlDbType.Char))
            .Parameters("@sodt").Value = SoDt

        End With

        myDat = New SqlDataAdapter(myCmd)
        myDat.Fill(myDtb)
        Return myDtb
        myCnn.Close()
    End Function

    Public Function GetWhereSoTc(ByVal SoTc As String, ByVal MaLoaiDt As String) As DataTable
        Dim myProjCnn As New ProjectConnection
        Dim myCnn As New SqlConnection
        Dim myDat As New SqlDataAdapter
        Dim myDtb As New DataTable

        myCnn = myProjCnn.GetConnection
        myCnn.Open()

        Dim myCmd As New SqlCommand
        With myCmd
            .Connection = myCnn
            .CommandType = CommandType.StoredProcedure
            .CommandText = "DuToanCt_GetWhereSoTc"

            .Parameters.Add(New SqlClient.SqlParameter("@sotc", SqlDbType.Char))
            .Parameters("@sotc").Value = SoTc

            .Parameters.Add(New SqlClient.SqlParameter("@maloaidt", SqlDbType.Char))
            .Parameters("@maloaidt").Value = MaLoaiDt
        End With

        myDat = New SqlDataAdapter(myCmd)
        myDat.Fill(myDtb)
        Return myDtb
        myCnn.Close()
    End Function

    Public Function Insert(ByVal DuToanCt As DuToanCt) As Boolean
        Dim myProjCnn As New ProjectConnection
        Dim myCnn As New SqlConnection
        Dim myDat As New SqlDataAdapter
        Dim myDtb As New DataTable

        myCnn = myProjCnn.GetConnection
        myCnn.Open()

        Dim myCmd As New SqlCommand
        With myCmd
            .Connection = myCnn
            .CommandType = CommandType.StoredProcedure
            .CommandText = "DuToanCt_Insert"

            .Parameters.Add(New SqlClient.SqlParameter("@sodt", SqlDbType.Char))
            .Parameters("@sodt").Value = DuToanCt.SoDt

            .Parameters.Add(New SqlClient.SqlParameter("@ma", SqlDbType.Int))
            .Parameters("@ma").Value = DuToanCt.Ma

            .Parameters.Add(New SqlClient.SqlParameter("@sl", SqlDbType.Decimal))
            .Parameters("@sl").Value = DuToanCt.Sl

            .Parameters.Add(New SqlClient.SqlParameter("@return", SqlDbType.Bit)).Direction = ParameterDirection.ReturnValue
            .ExecuteNonQuery()
        End With

        If myCmd.Parameters("@return").Value = 1 Then
            myCnn.Close()
            myCnn.Dispose()
            Return True
        Else
            myCnn.Close()
            myCnn.Dispose()
            Return False
        End If
    End Function

    Public Function Delete(ByVal SoDt As String) As Boolean
        Dim myProjCnn As New ProjectConnection
        Dim myCnn As New SqlConnection
        Dim myDat As New SqlDataAdapter
        Dim myDtb As New DataTable

        myCnn = myProjCnn.GetConnection
        myCnn.Open()

        Dim myCmd As New SqlCommand
        With myCmd
            .Connection = myCnn
            .CommandType = CommandType.StoredProcedure
            .CommandText = "DuToanCt_Delete"

            .Parameters.Add(New SqlClient.SqlParameter("@sodt", SqlDbType.Char))
            .Parameters("@sodt").Value = SoDt

            .Parameters.Add(New SqlClient.SqlParameter("@return", SqlDbType.Bit)).Direction = ParameterDirection.ReturnValue
            .ExecuteNonQuery()
        End With

        If myCmd.Parameters("@return").Value = 1 Then
            myCnn.Close()
            myCnn.Dispose()
            Return True
        Else
            myCnn.Close()
            myCnn.Dispose()
            Return False
        End If
    End Function


End Class

